using System;
using System.Collections.Generic;

namespace OracleInternal.Network
{
	internal class AnoService
	{
		internal const int ACCEPTED = 0;

		internal const int REJECTED = 1;

		internal const int REQUESTED = 2;

		internal const int REQUIRED = 3;

		internal const string AUTHENTICATION_NTS = "NTS";

		internal const string AUTHENTICATION_RADIUS = "RADIUS";

		internal const string AUTHENTICATION_KERBEROS5 = "KERBEROS5";

		internal const string AUTHENTICATION_TCPS = "TCPS";

		internal const string ENCRYPTION_RC4_40 = "RC4_40";

		internal const string ENCRYPTION_RC4_56 = "RC4_56";

		internal const string ENCRYPTION_RC4_128 = "RC4_128";

		internal const string ENCRYPTION_RC4_256 = "RC4_256";

		internal const string ENCRYPTION_DES40C = "DES40C";

		internal const string ENCRYPTION_DES56C = "DES56C";

		internal const string ENCRYPTION_3DES112 = "3DES112";

		internal const string ENCRYPTION_3DES168 = "3DES168";

		internal const string ENCRYPTION_AES128 = "AES128";

		internal const string ENCRYPTION_AES192 = "AES192";

		internal const string ENCRYPTION_AES256 = "AES256";

		internal const string CHECKSUM_MD5 = "MD5";

		internal const string CHECKSUM_SHA1 = "SHA1";

		internal const string CHECKSUM_SHA512 = "SHA512";

		internal const string CHECKSUM_SHA256 = "SHA256";

		internal const string CHECKSUM_SHA384 = "SHA384";

		internal const string ANO_ACCEPTED = "ACCEPTED";

		internal const string ANO_REJECTED = "REJECTED";

		internal const string ANO_REQUESTED = "REQUESTED";

		internal const string ANO_REQUIRED = "REQUIRED";

		internal AnoCommunication m_anoComm;

		internal SessionContext m_sessCtx;

		internal List<int> m_userChoiceDriversId;

		internal byte[] m_selectedDrivers;

		internal int m_service;

		internal long m_version;

		internal int m_level;

		internal int m_algID = -1;

		internal virtual int Initialize(SessionContext sessCtx)
		{
			m_sessCtx = sessCtx;
			m_anoComm = m_sessCtx.m_ano.m_anoComm;
			m_level = 0;
			m_selectedDrivers = new byte[0];
			return 1;
		}

		internal virtual void ReceiveServiceData(int numSubPackets)
		{
			throw new NotImplementedException("ReceiveServiceData");
		}

		internal virtual void ValidateResponse()
		{
			throw new NotImplementedException("ValidateResponse");
		}

		internal int NumberOfBytesNeeded()
		{
			return 8 + GetServiceDataLength();
		}

		internal virtual int GetServiceDataLength()
		{
			return 12 + m_selectedDrivers.Length;
		}

		internal void SendHeader(int serviceSubPackets)
		{
			m_anoComm.WriteUB2(m_service);
			m_anoComm.WriteUB2(serviceSubPackets);
			m_anoComm.WriteUB4(0L);
		}

		internal virtual void SendServiceData()
		{
			SendHeader(2);
			m_anoComm.SendVersion();
			m_anoComm.SendRaw(m_selectedDrivers);
		}

		internal static int[] ReceiveHeader(AnoCommunication anoComm)
		{
			return new int[3]
			{
				anoComm.ReadUB2(),
				anoComm.ReadUB2(),
				(int)anoComm.ReadUB4()
			};
		}

		internal void ReceiveSelection(int numSubPackets)
		{
			ReceiveServiceData(numSubPackets);
			ValidateResponse();
		}

		internal virtual void ActivateAlgorithm()
		{
		}

		internal void createDriversListWithLevel(ref List<int> userChoiceDriversId, int level)
		{
			switch (level)
			{
			case 0:
				userChoiceDriversId.Insert(0, 0);
				break;
			case 1:
				userChoiceDriversId.Clear();
				userChoiceDriversId.Add(0);
				break;
			case 2:
				userChoiceDriversId.Add(0);
				break;
			default:
				throw new NetworkException(-6304);
			case 3:
				break;
			}
		}

		internal static int translateAnoValue(string level)
		{
			int result = 0;
			if (level != null)
			{
				result = ((!level.Equals("ACCEPTED", StringComparison.InvariantCultureIgnoreCase)) ? (level.Equals("REQUESTED", StringComparison.InvariantCultureIgnoreCase) ? 2 : (level.Equals("REQUIRED", StringComparison.InvariantCultureIgnoreCase) ? 3 : (level.Equals("REJECTED", StringComparison.InvariantCultureIgnoreCase) ? 1 : (-1)))) : 0);
			}
			return result;
		}

		internal static string[] ValidateUserChoiceDrivers(string[] userList, string[] availList, bool defaultIsAll = true)
		{
			bool num = userList == null || userList.Length == 0;
			bool flag = false;
			bool flag2 = false;
			if (num)
			{
				if (defaultIsAll)
				{
					flag = true;
				}
				else
				{
					flag2 = true;
				}
			}
			else if (userList.Length == 1 && string.Equals(userList[0], "ALL", StringComparison.InvariantCultureIgnoreCase))
			{
				flag = true;
			}
			else if (userList.Length == 1 && string.Equals(userList[0], "NONE", StringComparison.InvariantCultureIgnoreCase))
			{
				flag2 = true;
			}
			string[] array;
			if (flag)
			{
				if (availList[0] == "")
				{
					array = new string[availList.Length - 1];
					Array.Copy(availList, 1, array, 0, array.Length);
				}
				else
				{
					array = availList;
				}
			}
			else if (flag2)
			{
				array = null;
			}
			else
			{
				for (int i = 0; i < userList.Length; i++)
				{
					if (string.IsNullOrEmpty(userList[i]))
					{
						throw new NetworkException(12649);
					}
					bool flag3 = false;
					for (int j = 0; j < availList.Length; j++)
					{
						if (string.Equals(availList[j], userList[i], StringComparison.InvariantCultureIgnoreCase))
						{
							flag3 = true;
							break;
						}
					}
					if (!flag3)
					{
						throw new NetworkException(12649);
					}
				}
				array = userList;
			}
			return array;
		}

		internal byte GetDriverID(string[] driverClasses, string str)
		{
			for (byte b = 0; b < driverClasses.Length; b = (byte)(b + 1))
			{
				if (str.Equals(driverClasses[b], StringComparison.InvariantCultureIgnoreCase))
				{
					return b;
				}
			}
			throw new NetworkException(-6309);
		}
	}
}
